<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/7 0007
 * Time: 11:50
 */
require_once 'Round.php';
$sentinels = [
    ['ip' => '0.0.0.0', 'port' => '22530'],
//    ['ip' => '127.0.0.1', 'port' => '22531'],
//    ['ip' => '127.0.0.1', 'port' => '22532']
];

$redis = new Redis();
$ipPost = $sentinels[array_rand($sentinels)];

$redis->connect($ipPost['ip'], $ipPost['port']);

$slaveInfos = $redis->rawCommand('SENTINEL', 'slaves', 'mymaster');

$slaves = [];
foreach ($slaveInfos as $slave) {
    $slaves[] = ['ip' => $slave[3], 'port' => $slave[5]];
}
//模拟客户端访问轮训子节点获得数据
swoole_timer_tick(600, function () use ($slaves) {
    $slave = Round::select($slaves);
    var_dump($slave);
    try {
        $redis = new Redis();
        $redis->connect($slave['ip'], $slave['port']);
        var_dump($slave, $redis->get('test'));
    } catch (RedisException $exception) {
        var_dump($exception->getMessage());
    }
});